package com.situ.vivamarket.model.search;

import com.situ.vivamarket.model.Admin;
import lombok.ToString;
import org.springframework.util.StringUtils;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;


public class AdminSearchBean extends Admin {
    private String credExpireTimeRange;
    private LocalDateTime credExpireTimeFrom;
    private LocalDateTime credExpireTimeTo;
    private String lastLoginTimeRange;
    private LocalDateTime lastLoginTimeFrom;
    private LocalDateTime lastLoginTimeTo;
//    直接使用setter方法，当前端使用反射填充数据的时候顺带着就给设置了From和To
    public void setCredExpireTimeRange(String credExpireTimeRange) {
        this.credExpireTimeRange = credExpireTimeRange;
        if (StringUtils.hasText(credExpireTimeRange)) {
            String[] range = credExpireTimeRange.split("\\s*~\\s*");
            credExpireTimeFrom = LocalDateTime.parse(range[0], DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
            credExpireTimeTo = LocalDateTime.parse(range[1], DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
        }
    }
    public void setLastLoginTimeRange(String lastLoginTimeRange) {
        this.lastLoginTimeRange = lastLoginTimeRange;
        if (StringUtils.hasText(lastLoginTimeRange)) {
            String[] range = lastLoginTimeRange.split("\\s*~\\s*");
            lastLoginTimeFrom = LocalDateTime.parse(range[0], DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
            lastLoginTimeTo = LocalDateTime.parse(range[1], DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
        }
    }

}
